<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/pc/jsp/common/common.jsp"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdMAHomeClass"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdUserAuthClass"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdOrderDataClass"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdOweClass"%>

<% 
 String userid=(String)CacheClass.isLogin(request,response);
 if(CacheClass.getIntValue(userid)==0)
 {
 	out.println("<script language='JavaScript'>alert('您还没有登陆！');location.href=document.referrer;</script>"); //后退并刷新
 	return;
 } 
 CrowdMAHomeClass obj= WebFunction.getMAHomeInfo(request,response);
 if(obj==null)
 {
	 out.println("<script language='JavaScript'>alert('白条放贷公司不存在，或平台已中止与供公司合作，暂不开放白条服务！');window.history.back(-1);</script>");
	 return;
 }
 CrowdUserAuthClass user= WebFunction.getUserInfo(request,response);
 if(user==null)
 {
	 out.println("<script language='JavaScript'>alert('用户不存在，或被平台禁用，请联系客服！');window.history.back(-1);</script>");
	 return;
 } 
  //取得目前可赎回的众筹订单
 List<CrowdOrderDataClass> list=WebFunction.getUserOwe2List(request, response);
%>
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <title>抵押赎回</title>
</head>
<body class='bcf'>


<div class="of jz" style="width: 92%;">
 <%if(list==null) return; for(CrowdOrderDataClass tmp:list){
     if(tmp.childlist==null || tmp.childlist.size()==0) break;
     CrowdOweClass owe2=tmp.childlist.get(0);%>
    <div class="w100 of bcf br6" style="margin:15px 0 20px;">
        <div class="clearfix of" style="margin-top:15px;">
            <div class="ya tc fl">
                押
            </div>
            <p class="fl f20 c3"><%=tmp.projectname %></p>
        </div>
        <div class="clearfix w100 pr" style="margin-left: 78px;padding: 6px 0;border-bottom: 1px dashed #e7e7e7">
            <div class="wrapper" style="position: absolute;left: -54px;top: 32px;margin: 0;z-index: 3;">
                <span><input type="checkbox"class="input_check" id="check<%=tmp.orderid%>" onclick="toTotal(<%=tmp.orderid%>,<%=tmp.totalrmb %>,<%=owe2.refundsrmb %>);"><label for="check<%=tmp.orderid%>"></label></span>
            </div>
            <div class="fl" style="width: 160px;margin-left: 10px;">
                <p class="f16 c6">商品数量(份)</p>
                <p class="c6 f19 fw500"><span style="font-size: 24px;"><%=tmp.ordernum %></span></p>
            </div>
            <div class="fl pr" style="width: 180px;">
                <div class="pa" style="top: 3px;width: 1px;height: 35px;background: #e7e7e7;left: -53px;"></div>
                <div class="pa" style="top: 3px;width: 1px;height: 35px;background: #e7e7e7;right: 38px;"></div>
                <p class="f16 c6">金额(元)</p>
                <p class="c6 f19 fw500"><span style="font-size: 24px;"><%=tmp.totalrmb %></span></p>
            </div>
            <div class="fl" style="width: 190px">
                <p class="f16 c6">抵押获资金</p>
                <p class="c6 f19 fw500"><span style="font-size: 24px;"><%=tmp.owermb %></span></p>
            </div>
            <div class="fl pr" style="width: 200px;">
                <div class="pa" style="top: 3px;width: 1px;height: 35px;background: #e7e7e7;left: -53px;"></div>
                <p class="f16 c6">押抵日期</p>
                <p class="c6 f19 fw500"><span style="font-size: 16px;"><%=owe2.owetimeAbout %></span></p>
            </div>            
        </div>
        <div class="clearfix of w100" style="padding: 16px 0;border-bottom: 1px solid #e7e7e7">
            <div class="fl" style="width: 160px;margin-left: 89px;">
                <p class="f16 c6">月息</p>
                <p class="corange f19 fw500"><span style="font-size: 24px;"><%=owe2.owegeinteres %></span>%</p>
            </div>
            <div class="fl pr" style="width: 180px;">
                <div class="pa" style="top: 3px;width: 1px;height: 35px;background: #e7e7e7;left: -53px;"></div>
                <div class="pa" style="top: 3px;width: 1px;height: 35px;background: #e7e7e7;right: 38px;"></div>
                <p class="f16 c6">锁定期(天)</p>
                <p class="corange f19 fw500"><span style="font-size: 24px;"><%=owe2.owedays %></span></p>
            </div>
            <div class="fl" style="width: 190px">
                <p class="f16 c6">需赎回资金</p>
                <p class="cred f19 fw500"><span style="font-size: 24px;"><%=owe2.refundsrmb %></span></p>
            </div>
            <div class="fl pr" style="width: 200px;">
                <div class="pa" style="top: 3px;width: 1px;height: 35px;background: #e7e7e7;left: -53px;"></div>
                <p class="f16 c6">赎回截止日期</p>
                <p class="cred f19 fw500"><span style="font-size: 24px;"> </span><span style="font-size: 16px;"><%=owe2.owefinishAbout %>前</span></p>
            </div>
        </div>
    </div>
<%} %>
</div>


<div class="of bcf br6" style="padding-left: 138px;">
    <p class="c3 fw500" style="font-size: 25px;margin-top: 25px;margin-bottom: 20px;">确认还贷赎回抵押<span style="font-size: 17px;">(【可用抵押金】须大于等于【需还贷资金】)</span></p>
    <div class="clearfix of">
    	<p class="fl f17 c6 mgt10" style="width: 344px;">抵押资产：<span class="c3" style="font-size: 26px;" id="rmb1">0</span><span style="font-size: 21px;"></span></p>
    	<p class="fr f17 c6 mgt10" style="width: 344px;">需还贷资金：<span class="cred" style="font-size: 26px;" id="rmb2">0</span><span style="font-size: 21px;"></span></p>
    </div>
    <div class="clearfix of">
        <p class="fl f17 c6 mgt10" style="width: 344px;">当前可用资金：<span class="corange" style="font-size: 26px;" id="rmb3"><%=user.nowrmb  %><span style="font-size: 21px;"></span></span></p>
        <p class="fr f17 c6 mgt10" style="width: 344px;">其中可用抵押金：<span class="cred" style="font-size: 26px;" id="rmb4"><%=user.principlelrmb %><span style="font-size: 21px;"></span></span></p>
    </div>
    <div class="mgt10 clearfix of mgb32">
        <input type="button" value="确认还贷" name="" id="btnok"  onclick="toPayBack();"  class="cf bcblue br3 mgt10 tc cursor fl" style="font-size: 24px;height: 55px;line-height: 55px;width: 318px;display:none "/>
        <input type="button" value="确认还贷" name="" id="btndisable"  disabled="disabled" class="cf bcblue br3 mgt10 tc cursor fl" style="font-size: 24px;height: 55px;line-height: 55px;width: 318px;background: #bbb;cursor: not-allowed;"/>
       
        <p id="messinfo" class="f16 mgl10 fl" style="color:#52bb44;margin-top: 44px; display:none">您当前的【可用抵押金】金额不足以还贷</p>
    </div>
</div>
<script>
   var order=[];
   function toTotal(orderid,rmb1,rmb2)
   {
        var rmb1old=$.trim($("#rmb1").html());
   		var rmb2old=$.trim($("#rmb2").html());
   		var rmb4=$.trim($("#rmb4").html());
   		
   		var r1=0;
   		var r2=0;
        if($('#check'+orderid).prop('checked'))
        {
           	r1=rmb1old*1.00+rmb1;
   			r2=rmb2old*1.00+rmb2;
   			order.push(orderid);
        }
        else
        {
	        r1=rmb1old*1.00-rmb1;
	   		r2=rmb2old*1.00-rmb2;
	   		order.splice(jQuery.inArray(orderid,order),1); 
            //其中jQuery.inArray('b',arrList)是b这个元素在数组arrList 中的位置  splice(index,1)函数中第一个参数index是要删除元素在数组中的位置，第二个参数是要删除的数量
        }
        if(order.length>0)
        {
        	$("#btnok").show();
        	$("#btndisable").hide();
        }
        else
        {
            $("#btndisable").show();
        	$("#btnok").hide();
        }
        
        if(rmb4*1.00<r2)
        {
           $("#messinfo").show();
        }
        else
        {
           $("#messinfo").hide();
        }
   		$("#rmb1").html(r1);
   		$("#rmb2").html(r2);
   
   }
   
   function toPayBack()
   {
   	$.ajax({
            url: "PlugServlet ",
            data: JSON.stringify({m:1757,orderidlist :order.toString()}),
            type: 'post',
            dataType: 'json',
            contentType:"application/json;charset=utf-8",
            beforeSend: function () {
                $("#loadingfDiv").fadeIn();
            },
            success: function (data) {
            	console.log(data);
   	           if(data['state']==1)
	           {
	           		layer.alert(data.info);
	           }
	           else
	           {
	           		layer.alert(data.info);
	           }
           },
            error: function (data) {
                layer.alert(data.msg);
                return false;
            },
            complete: function () {
                $("#loadingfDiv").fadeOut();
            }
        });
   
   }
    $(function () {

    })
</script>
</body>
</html>